package com.telit.firecommand.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.telit.common.entity.DataReturn;
import com.telit.firecommand.entity.CadPlotAttachment;
import com.telit.firecommand.service.ICadPlotAttachmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 联动标绘详情表 前端控制器
 * </p>
 *
 * @author yummy
 * @since 2021-09-15
 */
@RestController
@RequestMapping("/cad-plot-attachment")
@Api(tags = "联动标绘详情表", description = "/cad-plot-attachment")
public class CadPlotAttachmentController {

    private Logger log = LoggerFactory.getLogger(getClass());

    @Resource
    private ICadPlotAttachmentService cadPlotAttachmentService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public DataReturn add(@RequestBody CadPlotAttachment cadPlotAttachment) {
        long value = cadPlotAttachmentService.add(cadPlotAttachment);
        return DataReturn.ok(value);
    }

    @GetMapping("/delete/{id}")
    @ApiImplicitParam(name = "id", value = "配置ID", paramType = "path", dataType = "Integer")
    public DataReturn delete(@PathVariable("id") Integer id) {
        int value = cadPlotAttachmentService.delete(id);
        return DataReturn.ok(value);
    }

    @GetMapping("/deleteBatch")
    @ApiImplicitParam(name = "ids", value = "配置ID数组", paramType = "query", dataType = "integer[]")
    public DataReturn deleteBatch(Integer[] ids) {
        List<Integer> values = cadPlotAttachmentService.deleteBatch(ids);
        return DataReturn.ok(values);
    }

    @PostMapping("/update")
    @ApiOperation("修改")
    public DataReturn update(@RequestBody CadPlotAttachment cadPlotAttachment) {
        cadPlotAttachmentService.updateData(cadPlotAttachment);
        return DataReturn.ok();
    }

    @PostMapping("/search")
    @ApiOperation("条件查询+分页")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "当前页面", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "rows", value = "每页记录数", dataType = "int", paramType = "query")})
    public DataReturn findListByPage(@RequestBody(required = false) CadPlotAttachment cadPlotAttachment, Integer page,
                                     Integer pageCount) {
        IPage<CadPlotAttachment> cadPlotAttachmentPage = cadPlotAttachmentService.findListByPage(cadPlotAttachment,
                page, pageCount);
        Map<String, Object> retMap = new HashMap<String, Object>();
        retMap.put("cadPlotAttachment", cadPlotAttachmentPage.getRecords());
        retMap.put("total", cadPlotAttachmentPage.getTotal());
        return DataReturn.ok(retMap);
    }

    @PostMapping("/searchNoPage")
    @ApiOperation("条件查询")
    public DataReturn searchNoPage(@RequestBody(required = false) CadPlotAttachment cadPlotAttachment) {
        List<CadPlotAttachment> cadPlotAttachmentList = cadPlotAttachmentService.searchNoPage(cadPlotAttachment);
        return DataReturn.ok(cadPlotAttachmentList);
    }

    @GetMapping("/findOne/{id}")
    @ApiOperation("根据id获取配置实体")
    @ApiImplicitParam(name = "id", value = "配置ID", paramType = "path", dataType = "Long")
    public DataReturn findById(@PathVariable Integer id) {
        CadPlotAttachment cadPlotAttachment = cadPlotAttachmentService.findById(id);
        return DataReturn.ok(cadPlotAttachment);
    }

}
